/*
 * FXGL - JavaFX Game Library. The MIT License (MIT).
 * Copyright (c) AlmasB (almaslvl@gmail.com).
 * See LICENSE for details.
 */

package com.windea.study.kotlin.fxgl.sample.sandbox

import com.almasb.fxgl.app.*
import com.almasb.fxgl.dsl.*
import com.almasb.fxgl.entity.*
import com.almasb.fxgl.input.*
import javafx.scene.input.*
import javafx.scene.paint.*
import javafx.scene.shape.*

class CustomResizeSample : GameApplication() {
	private lateinit var player: Entity
	
	override fun initSettings(settings: GameSettings) {
		settings.isManualResizeEnabled = true
		settings.isPreserveResizeRatio = true
		settings.width = 1280
		settings.height = 720
		settings.title = "CustomResizeSample"
	}
	
	override fun initInput() {
		val input = getInput()
		input.addAction(object : UserAction("Up") {
			override fun onAction() {
				player.translateY(-5.0)
			}
		}, KeyCode.W)
		input.addAction(object : UserAction("Right") {
			override fun onAction() {
				player.translateX(5.0)
			}
		}, KeyCode.D)
		input.addAction(object : UserAction("Down") {
			override fun onAction() {
				player.translateY(5.0)
			}
		}, KeyCode.S)
		input.addAction(object : UserAction("Left") {
			override fun onAction() {
				player.translateX(-5.0)
			}
		}, KeyCode.A)
	}
	
	override fun initGame() {
		val gameWorld = getGameWorld()
		gameWorld.addEntityFactory(DemoEntityFactory())
		player = gameWorld.spawn("player", SpawnData(200.0, 200.0))
	}
	
	override fun initUI() {
		val gameScene = getGameScene()
		gameScene.addUINode(Rectangle(getAppWidth().toDouble(), getAppHeight().toDouble(), Color(.0, .0, 1.0, .5)))
	}
	
	inner class DemoEntityFactory : EntityFactory {
		
		@Spawns("player")
		fun newPlayer(data: SpawnData): Entity {
			return entityBuilder()
				.at(data.x, data.y)
				.view(Rectangle(100.0, 100.0, Color.GREEN))
				.build()
		}
	}
}


fun main(args: Array<String>) {
	GameApplication.launch(CustomResizeSample::class.java, args)
}

